﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using MvcLibrary.Repository;

namespace VietPremier.Areas.AdminCP.Controllers
{
    public class LoginController : Controller
    {
        //
        // GET: /AdminCP/Login/

        public ActionResult Index()
        {
            return View();
        }
        public JsonResult CheckId(string username, string password)
        {
            EntityAdmin user = new EntityAdmin();
            user.Username = " ";
            try
            {

                dbVietPremierDataContext db = new dbVietPremierDataContext();

                Security ser = new Security();
                string passHex = ser.GetHashPassword(password);

                var adminquery = (from p in db.EntityAdmins
                                  where p.Username == username && p.Password == passHex
                                  select p).Single();


                if (adminquery != null)
                {
                    user = adminquery;
                    Session["User"] = user; // tao session


                }
                return Json(user);
            }
            catch
            {
                return Json(user);
            }
        }
    }
}
